{% extends "base.html" %}

{% block title %}分析员工作台 - 协同调度信息系统{% endblock %}

{% block content %}
<div class="row">
    <!-- 待分析数据 -->
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">
                    <i class="fas fa-clock"></i> 待分析数据
                    <span class="badge bg-warning ms-2">{{ pending_recon|length }}</span>
                </h5>
            </div>
            <div class="card-body">
                {% if pending_recon %}
                    {% for data in pending_recon %}
                    <div class="card mb-3 border-warning">
                        <div class="card-body">
                            <h6 class="card-title">
                                <i class="fas fa-search"></i> {{ data.title }}
                            </h6>
                            <p class="card-text">
                                <small class="text-muted">
                                    <strong>目标:</strong> {{ data.target_system }} | 
                                    <strong>类型:</strong> 
                                    {% if data.data_type == 'network' %}网络信息
                                    {% elif data.data_type == 'system' %}系统信息
                                    {% elif data.data_type == 'vulnerability' %}漏洞信息
                                    {% elif data.data_type == 'user' %}用户信息
                                    {% elif data.data_type == 'service' %}服务信息
                                    {% else %}其他
                                    {% endif %} |
                                    <strong>优先级:</strong> 
                                    <span class="priority-badge priority-{{ data.priority }}">
                                        {% if data.priority == 'low' %}低
                                        {% elif data.priority == 'medium' %}中
                                        {% elif data.priority == 'high' %}高
                                        {% elif data.priority == 'critical' %}紧急
                                        {% endif %}
                                    </span>
                                </small>
                            </p>
                            <p class="card-text">
                                {{ data.content[:100] }}{% if data.content|length > 100 %}...{% endif %}
                            </p>
                            <div class="d-flex justify-content-between align-items-center">
                                <small class="text-muted">
                                    {{ data.created_at.strftime('%Y-%m-%d %H:%M') }}
                                </small>
                                <a href="{{ url_for('analyze_data', recon_id=data.id) }}" 
                                   class="btn btn-sm btn-primary">
                                    <i class="fas fa-chart-line"></i> 开始分析
                                </a>
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                {% else %}
                    <div class="text-center py-4">
                        <i class="fas fa-check-circle fa-2x text-success mb-2"></i>
                        <p class="text-muted mb-0">暂无待分析数据</p>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>

    <!-- 我的分析结果 -->
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">
                    <i class="fas fa-chart-line"></i> 我的分析结果
                    <span class="badge bg-info ms-2">{{ analysis_results|length }}</span>
                </h5>
            </div>
            <div class="card-body">
                {% if analysis_results %}
                    {% for result in analysis_results %}
                    <div class="card mb-3 border-info">
                        <div class="card-body">
                            <h6 class="card-title">
                                <i class="fas fa-chart-bar"></i> 
                                {% if result.analysis_type == 'threat' %}威胁分析
                                {% elif result.analysis_type == 'vulnerability' %}漏洞分析
                                {% elif result.analysis_type == 'opportunity' %}机会分析
                                {% elif result.analysis_type == 'comprehensive' %}综合分析
                                {% endif %}
                            </h6>
                            <p class="card-text">
                                <small class="text-muted">
                                    <strong>置信度:</strong> 
                                    <span class="badge bg-secondary">
                                        {% if result.confidence_level == 'low' %}低
                                        {% elif result.confidence_level == 'medium' %}中
                                        {% elif result.confidence_level == 'high' %}高
                                        {% endif %}
                                    </span> |
                                    <strong>状态:</strong> 
                                    <span class="status-badge status-{{ result.status }}">
                                        {% if result.status == 'pending' %}待审核
                                        {% elif result.status == 'reviewed' %}已审核
                                        {% elif result.status == 'approved' %}已批准
                                        {% endif %}
                                    </span>
                                </small>
                            </p>
                            <p class="card-text">
                                <strong>主要发现:</strong><br>
                                {{ result.findings[:150] }}{% if result.findings|length > 150 %}...{% endif %}
                            </p>
                            <div class="d-flex justify-content-between align-items-center">
                                <small class="text-muted">
                                    {{ result.created_at.strftime('%Y-%m-%d %H:%M') }}
                                </small>
                                <button class="btn btn-sm btn-outline-info" 
                                        data-bs-toggle="modal" 
                                        data-bs-target="#viewAnalysisModal{{ result.id }}">
                                    <i class="fas fa-eye"></i> 查看详情
                                </button>
                            </div>
                        </div>
                    </div>

                    <!-- 查看分析详情模态框 -->
                    <div class="modal fade" id="viewAnalysisModal{{ result.id }}" tabindex="-1">
                        <div class="modal-dialog modal-lg">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title">
                                        {% if result.analysis_type == 'threat' %}威胁分析
                                        {% elif result.analysis_type == 'vulnerability' %}漏洞分析
                                        {% elif result.analysis_type == 'opportunity' %}机会分析
                                        {% elif result.analysis_type == 'comprehensive' %}综合分析
                                        {% endif %}
                                    </h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                                </div>
                                <div class="modal-body">
                                    <div class="row mb-3">
                                        <div class="col-md-6">
                                            <p><strong>置信度:</strong> 
                                                <span class="badge bg-secondary">
                                                    {% if result.confidence_level == 'low' %}低
                                                    {% elif result.confidence_level == 'medium' %}中
                                                    {% elif result.confidence_level == 'high' %}高
                                                    {% endif %}
                                                </span>
                                            </p>
                                        </div>
                                        <div class="col-md-6">
                                            <p><strong>状态:</strong> 
                                                <span class="status-badge status-{{ result.status }}">
                                                    {% if result.status == 'pending' %}待审核
                                                    {% elif result.status == 'reviewed' %}已审核
                                                    {% elif result.status == 'approved' %}已批准
                                                    {% endif %}
                                                </span>
                                            </p>
                                        </div>
                                    </div>
                                    
                                    <h6>分析发现:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ result.findings }}</pre>
                                    </div>
                                    
                                    <h6>建议措施:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ result.recommendations }}</pre>
                                    </div>
                                    
                                    {% if result.priority_targets %}
                                    <h6>优先目标:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ result.priority_targets }}</pre>
                                    </div>
                                    {% endif %}
                                    
                                    {% if result.suggested_actions %}
                                    <h6>建议行动:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ result.suggested_actions }}</pre>
                                    </div>
                                    {% endif %}
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                {% else %}
                    <div class="text-center py-4">
                        <i class="fas fa-chart-line fa-2x text-muted mb-2"></i>
                        <p class="text-muted mb-0">暂无分析结果</p>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<!-- 工作流程说明 -->
<div class="row mt-4">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0">
                    <i class="fas fa-info-circle"></i> 分析员工作流程
                </h6>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-3 text-center">
                        <div class="mb-3">
                            <i class="fas fa-search fa-2x text-primary mb-2"></i>
                            <h6>接收数据</h6>
                            <small class="text-muted">接收侦察员提交的侦察数据</small>
                        </div>
                    </div>
                    <div class="col-md-3 text-center">
                        <div class="mb-3">
                            <i class="fas fa-chart-line fa-2x text-info mb-2"></i>
                            <h6>深度分析</h6>
                            <small class="text-muted">对数据进行威胁、漏洞或机会分析</small>
                        </div>
                    </div>
                    <div class="col-md-3 text-center">
                        <div class="mb-3">
                            <i class="fas fa-lightbulb fa-2x text-warning mb-2"></i>
                            <h6>提供建议</h6>
                            <small class="text-muted">基于分析结果提供行动建议</small>
                        </div>
                    </div>
                    <div class="col-md-3 text-center">
                        <div class="mb-3">
                            <i class="fas fa-paper-plane fa-2x text-success mb-2"></i>
                            <h6>提交结果</h6>
                            <small class="text-muted">将分析结果提交给决策员审核</small>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
